home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DSIIC2.ARJ / L_MAIN.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  6KB  |  250 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_MAIN.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <dos.h>
  7. #include <string.h>
  8. #include <ctype.h>   /* [* */
  9. #include <stdlib.h>  /* [* */
  10. /* define our external variables */
  11. /* window definitions */
  12.  
  13. struct screen_structure scr;
  14. struct window_structure w[MAX_WINDOW+1];
  15. struct help_structure hlp;
  16.  
  17. int main(int argc,char *argv[])
  18. {
  19. extern struct screen_structure scr;
  20. extern struct window_structure w[];
  21. extern struct help_structure hlp;
  22.  
  23.   int i;
  24.   unsigned int seg,off;
  25.   long l;
  26.   char string[10];
  27.   int return_code;
  28.  
  29. set_screen_attr();      /* set screen attributes */
  30. test_dv();              /* check for DesqView */
  31.  
  32. /* extract segment and offset of screen buffer */
  33. seg=FP_SEG(scr.buffer); off=FP_OFF(scr.buffer);
  34.  
  35. /* check command line values for override values */
  36.  if(argc>1)
  37.  for(i=1;i<=argc;i++){
  38.  
  39.    copy(argv[i],string,2,4); /* copy any values. i.e. r=30 */
  40.                              /* note: copy() is found in l_copy.c */
  41.    /* check for segment override */
  42.    if ( toupper(argv[i][0])=='S') if(atoi(string)) seg=atoi(string);
  43.  
  44.    /* check for offset override */
  45.    if ( toupper(argv[i][0])=='O') if(atoi(string)) off=atoi(string);
  46.  
  47.    /* check for row override */
  48.    if ( toupper(argv[i][0])=='R')
  49.     if(atoi(string)) scr.rows=atoi(string);
  50.  
  51.    /* chec for column override */
  52.    if ( toupper(argv[i][0])=='C')
  53.     if(atoi(string)) scr.columns=atoi(string);
  54.  
  55.    /* check for black & white override */
  56.    if ( toupper(argv[i][0])=='B') set_mode(BW_80);
  57.  
  58.    /* check for snow override (turn off snow avoidance)  */
  59.    if ( toupper(argv[i][0])=='N') scr.snow=FALSE;
  60.  }
  61.  
  62. scr.buffer=MAKE_FP(seg,off);
  63.  
  64. init_window();          /* initialize window structure */
  65. update_margins();
  66.                         /* initialize help structure */
  67. hlp.filename[0]='\0';   /* empty string (no current help file) */
  68.  
  69. /* set text which appears in window frame */
  70. strcpy(hlp.message,"Esc: to exit ");  
  71. hlp.page=0;                   /* page zero */
  72. hlp.x=1;                      /* upper left column of help window */
  73. hlp.y=1;                      /* upper left row of help window */
  74. hlp.interior_attr=scr.normal; /* set window interior to normal */
  75. hlp.frame_attr=scr.normal;    /* set window frame to normal */
  76.  
  77. return_code=start(argc,  argv);
  78. return(return_code);
  79. }
  80.  
  81.  
  82. static void init_window(void)
  83. {
  84. extern struct screen_structure scr;
  85. extern struct window_structure w[];
  86. int i;
  87.  
  88. /* initialize initial window (desk top) */
  89.   w[0].frame=FALSE;
  90.   wherexy(&w[0].x,&w[0].y); /* save current cursor location*/
  91.   what_cursor(&w[0].start,&w[0].end);
  92.   w[0].left=1;w[0].right=scr.columns;
  93.   w[0].top=1;w[0].bottom=scr.rows;
  94.   w[0].attribute=scr.normal;  /* assume default normal attribute */
  95.  
  96.  /* initialize window pointer array */
  97.  
  98.  for(i=0;i<=MAX_WINDOW;i++){
  99.   scr.list[i]=i;
  100.  }
  101. }
  102.  
  103.  
  104. /*****************************************************************
  105.  
  106.  Usage: static void set_screen_attr(void);
  107.  
  108.  Ascertains what type of graphics card is in use, sets external
  109.  text attributes and screen buffer address according.
  110.  
  111. *****************************************************************/
  112.  
  113. static void set_screen_attr(void)
  114. {
  115. extern struct  screen_structure scr;
  116. extern struct window_structure w[];
  117.  
  118.  what_mode(&scr.mode,&scr.page);  /*set current textmode and page */
  119.  
  120.  if(scr.mode==MONOCHROME) scr.mode = MONOCHROME;
  121.  
  122.  if(scr.mode==BW_40){      /* if 40 column BW set to 80 column */
  123.   set_mode(BW_80);
  124.   scr.mode =BW_80;
  125.  }
  126.  
  127.  if(scr.mode==COLOR_40){   /* if 40 column color, set to 80 column */
  128.        set_mode(COLOR_80);
  129.        scr.mode=COLOR_80;
  130.  }
  131.  
  132. /* set character attributes */
  133.  
  134.   if (scr.mode==BW_80){             /* set attributes for BW */
  135.     scr.normal=  set_color(WHITE,BLACK);
  136.     scr.inverse= set_color(BLACK,WHITE);
  137.    }
  138.  
  139.   if (scr.mode==COLOR_80){           /* set attributes for COLOR */
  140.     scr.normal=  set_color(WHITE,BLACK);
  141.     scr.inverse= set_color(BLACK,WHITE);
  142.    }
  143.  
  144.    if (scr.mode==MONOCHROME){    /* set attributes for MONOCHROME */
  145.     scr.normal = NORMAL;
  146.     scr.inverse = INVERSE;
  147.    }
  148.  
  149.     scr.current = scr.normal;   /* set screen attribute to normal */
  150.  
  151.  /* set screen buffer address */
  152.  if(scr.mode==MONOCHROME)
  153.     scr.buffer= (char far *)0xb0000000;    /* monochrome address */
  154.    else
  155.      scr.buffer=(char far *)0xb8000000;    /* color address */
  156.  
  157.   scr.rows=25;scr.columns=80;  /* assume standard values for now */
  158.   scr.update=TRUE;
  159.   scr.bold_caps=FALSE;
  160.   scr.ptr=0;scr.active=0;
  161.  
  162.   /* set snow flag if not ega and not monochrome */
  163.   scr.snow=  (!test_ega() && (scr.mode!=MONOCHROME));
  164.  
  165.   /* set screen margins */
  166.   scr.top=1;
  167.   scr.bottom=scr.rows;
  168.   scr.left=1;
  169.   scr.right=scr.columns;
  170.  
  171. }
  172.  
  173.  
  174. #if defined TURBOC
  175.  
  176. static void test_dv(void)
  177. {
  178. extern struct  screen_structure scr;
  179. int seg,off;
  180.  
  181.    struct REGPACK regs;
  182.  
  183.    seg = FP_SEG(scr.buffer);
  184.    off = FP_OFF(scr.buffer);
  185.  
  186.    regs.r_ax=0xfe00;
  187.  
  188.    regs.r_es= seg;
  189.    regs.r_di= off;
  190.  
  191.    intr(0x10, ®s);
  192.  
  193.  if(regs.r_es != seg || regs.r_di != off)
  194.  scr.buffer=MAKE_FP(regs.r_es,regs.r_di);
  195. }
  196. #endif
  197.  
  198.  
  199. #if defined QUICKC
  200.  
  201. static void test_dv(void)
  202. {
  203. extern struct  screen_structure scr;
  204. int seg,off;
  205.  
  206. union REGS inregs,outregs;
  207. struct SREGS segregs;
  208.  
  209.   seg = FP_SEG(scr.buffer);
  210.   off = FP_OFF(scr.buffer);
  211.  
  212.    inregs.h.ah=0xfe;
  213.    segregs.es= seg;
  214.    inregs.x.di= off;
  215.  
  216.    int86x(0x10, &inregs,&outregs,&segregs);
  217.  
  218.  if(segregs.es != seg || inregs.x.di != off)
  219.   scr.buffer=MAKE_FP(segregs.es,inregs.x.di);
  220.  
  221. }
  222. #endif
  223.  
  224.  
  225. int test_ega(void)
  226. {
  227.  union REGS reg;
  228.  
  229.  reg.h.ah = 0X12;         /* call an ega function */
  230.  reg.h.bl = 0X10;
  231.  reg.x.cx = 0Xffff;       /* stuff the register */
  232.  
  233.  int86(0X10, ®, ®);
  234.   if (reg.x.cx==0xffff) return (0); /* if it isn't changed, no ega */
  235.     else
  236.      return(1); /* contents changed, there is a ega */
  237. }
  238.  
  239.  
  240. void update_margins(void)
  241. {
  242. extern struct  screen_structure scr;
  243. extern struct window_structure w[];
  244.  
  245.  scr.top= w[scr.active].top;
  246.  scr.bottom= w[scr.active].bottom;
  247.  scr.left= w[scr.active].left;
  248.  scr.right= w[scr.active].right;
  249. }
  250.